<?php
  
 /*
function cetak_laporan_thp($komponen_id){
   
echo '
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>HRIS Krakatau Medika :: Printed out report</title> 
</head>

<body style="font:10px verdana;" onload = "javascript:breakeveryheader()"><pre>';
	$periode_id = isset($_GET['periode_id']) ? (int) $_GET['periode_id']: get_periode_gaji();
	$dperiode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$filenamedt = date('Y-m',strtotime($dperiode['tanggal']));
 
 
	$komponen = my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',$komponen_id);
	$bulans = array(
		1=>'Januari',
		2=>'Februari',
		3=>'Maret',
		4=>'April',
		5=>'Mei',
		6=>'Juni',
		7=>'Juli',
		8=>'Agustus',
		9=>'September',
		10=>'Oktober',
		11=>'November',
		12=>'Desember',
	);
	$bln = (int)date('m' ,strtotime($dperiode['tanggal']));
	$namabulan = $bulans[$bln];  
	$query = $query = " SELECT takehomepay FROM pr_gaji 
		WHERE periode_id={$periode_id}";
	$result = my_query($query);
	$total_record = my_num_rows($result);
	$total_page = ceil($total_record/40);
	$grand_nominal=0;
	for($n=1;$n<=$total_page;$n++):
	$st = ($n - 1 )*40;
 ?>
 
 
 <?php echo str_pad('P.T.  K R A K A T A U  M E D I K A',75," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad( 'DATA TAKE HOME PAY' ,75," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad('Periode  ( '. $namabulan.' '.date('Y').' )',75," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad(date('d-m-Y H:i'),35).str_pad('Hal : '.$n,40," ", STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); ?> 
 <?php echo str_pad( 'NO',6," ",STR_PAD_BOTH). str_pad( 'N.I.K',9 ). str_pad( 'N A M A',50 ) .str_pad('JUMLAH',10," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); 
 $query = "  SELECT karyawan_id , takehomepay FROM pr_gaji 
		WHERE periode_id={$periode_id} LIMIT $st,40"
	;

	$result = my_query($query);
	$i=$st;
	$nominal_page =0;
	while($ey = my_fetch_array($result)){
	$i++;
	$karyawan_temp=$ey['karyawan_id'];
	$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
	$jabatan =  loaddata_jabatan($karyawan['jabatan_id']);  
	$query = " SELECT takehomepay FROM pr_gaji 
		WHERE periode_id={$periode_id}
		AND karyawan_id=".$ey['karyawan_id']
	;
	$result1 = my_query($query);	
	$gajis = my_fetch_array($result1);
	$nominal_page += $gajis['takehomepay'];
	$grand_nominal +=$gajis['takehomepay'];
	
 ?> 
 <?php echo str_pad( $i.'  ',6," ",STR_PAD_LEFT). str_pad($karyawan['nik'] ,9 ). str_pad( $karyawan['nama'] ,50 ).  str_pad(rp_format($gajis['takehomepay']),10," ",STR_PAD_LEFT); ?>  <?php if(($i%5) ==0 && ($i%40) !=0)echo "\n";
 }
 ?> 
 <?php echo str_repeat('_',76); ?> 
 <?php echo str_pad( 'Sub total',15," ",STR_PAD_BOTH) . str_pad( ' ',40 ).str_pad(rp_format($nominal_page) ,20," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); ?> 
 <?php echo str_pad( ($n==$total_page ? " Grand t": " T").'otal',15 ) . str_pad( ' ',40 ).str_pad(rp_format($grand_nominal) ,20," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); ?>
 
 <?php if( $n == $total_page){  echo "\n\n "; 
  $bl = (int)date('m'); echo str_pad( str_pad('Cilegon, '.date('d').' '.$bulans[$bl].' '.date('Y').'     '  , 25, " ", STR_PAD_BOTH ),65," ",STR_PAD_LEFT); 
   echo "\n\n\n\n\n\n";
 echo str_pad( '('.str_pad( MAN_DEPARTEMEN_HEAD_OFFICE_NAME ,25," ",STR_PAD_BOTH).')  ',65," ",STR_PAD_LEFT);  
echo "\n";
 echo str_pad( ' '.str_pad( MAN_DEPARTEMEN_HEAD_OFFICE ,25," ",STR_PAD_BOTH).'   ',65," ",STR_PAD_LEFT); 
 } ?>
 <P>
 <?php    
 endfor; 
 ?>
<?php
	echo'
	
<script>
function breakeveryheader(){
if (!document.getElementById){
	alert("You need IE5 or NS6 to run this example")
	return
}
var thestyle=  "always" ;
for (i=0; i<document.getElementsByTagName("P").length; i++)
	document.getElementsByTagName("P")[i].style.pageBreakBefore=thestyle
}
//window.print();
</script>   
</body> 
</html>';
exit;	
}
 
function cetak_laporan_gapok($komponen_id){
   
echo '
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>HRIS Krakatau Medika :: Printed out report</title> 
</head>

<body style="font:10px verdana;" onload = "javascript:breakeveryheader()"><pre>';
	$periode_id = isset($_GET['periode_id']) ? (int) $_GET['periode_id']: get_periode_gaji();
	$dperiode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$filenamedt = date('Y-m',strtotime($dperiode['tanggal']));
 
 
	$komponen = my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',(int)$komponen_id);
	$bulans = array(
		1=>'Januari',
		2=>'Februari',
		3=>'Maret',
		4=>'April',
		5=>'Mei',
		6=>'Juni',
		7=>'Juli',
		8=>'Agustus',
		9=>'September',
		10=>'Oktober',
		11=>'November',
		12=>'Desember',
	);
	$bln = (int)date('m' ,strtotime($dperiode['tanggal']));
	$namabulan = $bulans[$bln];  
	$query = $query = " SELECT takehomepay FROM pr_gaji 
		WHERE periode_id={$periode_id}";
	$result = my_query($query);
	$total_record = my_num_rows($result);
	$total_page = ceil($total_record/40);
	$grand_nominal=0;
	for($n=1;$n<=$total_page;$n++):
	$st = ($n - 1 )*40;
 ?>
  
 <?php echo str_pad('P.T.  K R A K A T A U  M E D I K A',75," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad( 'DATA GAJI DIBAYAR' ,75," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad('Periode  ( '. $namabulan.' '.date('Y').' )',75," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad(date('d-m-Y H:i'),35).str_pad('Hal : '.$n,40," ", STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); ?> 
 <?php echo str_pad( 'NO',6," ",STR_PAD_BOTH). str_pad( 'N.I.K',9 ). str_pad( 'N A M A',50 ) .str_pad('JUMLAH',10," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); 
 $query = "  SELECT karyawan_id , gaji_dibayar FROM pr_gaji 
		WHERE periode_id={$periode_id} LIMIT $st,40"
	;
 
	$result = my_query($query);
	$i=$st;
	$nominal_page =0;
	while($ey = my_fetch_array($result)){
	$i++;
	$karyawan_temp=$ey['karyawan_id']; 
	$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
	$jabatan =  loaddata_jabatan($karyawan['jabatan_id']);  
	$query = " SELECT gaji_dibayar FROM pr_gaji 
		WHERE periode_id={$periode_id}
		AND karyawan_id=".$ey['karyawan_id']
	;
	$result1 = my_query($query);	
	$gajis = my_fetch_array($result1);
	$nominal_page += $gajis['gaji_dibayar'];
	$grand_nominal +=$gajis['gaji_dibayar'];
	
 ?> 
 <?php echo str_pad( $i.'  ',6," ",STR_PAD_LEFT). str_pad($karyawan['nik'] ,9 ). str_pad( $karyawan['nama'] ,50 ).  str_pad(rp_format($gajis['gaji_dibayar']),10," ",STR_PAD_LEFT); ?>  <?php if(($i%5) ==0 && ($i%40) !=0)echo "\n";
 }
 ?> 
 <?php echo str_repeat('_',76); ?> 
 <?php echo str_pad( 'Sub total',15," ",STR_PAD_BOTH) . str_pad( ' ',40 ).str_pad(rp_format($nominal_page) ,20," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); ?> 
 <?php echo str_pad( ($n==$total_page ? " Grand t": " T").'otal',15 ) . str_pad( ' ',40 ).str_pad(rp_format($grand_nominal) ,20," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',76); ?>
 
 <?php if( $n == $total_page){  echo "\n\n "; 
  $bl = (int)date('m'); echo str_pad( str_pad('Cilegon, '.date('d').' '.$bulans[$bl].' '.date('Y').'     '  , 25, " ", STR_PAD_BOTH ),65," ",STR_PAD_LEFT); 
   echo "\n\n\n\n\n\n";
 echo str_pad( '('.str_pad( MAN_DEPARTEMEN_HEAD_OFFICE_NAME ,25," ",STR_PAD_BOTH).')  ',65," ",STR_PAD_LEFT);  
echo "\n";
 echo str_pad( ' '.str_pad( MAN_DEPARTEMEN_HEAD_OFFICE ,25," ",STR_PAD_BOTH).'   ',65," ",STR_PAD_LEFT); 
 } ?>
 <P>
 <?php    
 endfor; 
 ?>
<?php
echo'
	
<script>
function breakeveryheader(){
if (!document.getElementById){
	alert("You need IE5 or NS6 to run this example")
	return
}
var thestyle=  "always" ;
for (i=0; i<document.getElementsByTagName("P").length; i++)
	document.getElementsByTagName("P")[i].style.pageBreakBefore=thestyle
}
//window.print();
</script>   
</body> 
</html>';
exit;	
}


	 */
function cetak_laporan($komponen_id , $pr_yearly_income_id){
  
echo '
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>HRIS Krakatau Medika :: Printed out report</title> 
</head>

<body style="font:10px verdana;" onload = "javascript:breakeveryheader()"><pre>';
	
	

	$komponen = my_get_data_by_id('pr_yearly_income_komponen','komponen_id',$komponen_id);  

	$filenamedt = $komponen['label'] ;
	$bulans = array(
		1=>'Januari',
		2=>'Februari',
		3=>'Maret',
		4=>'April',
		5=>'Mei',
		6=>'Juni',
		7=>'Juli',
		8=>'Agustus',
		9=>'September',
		10=>'Oktober',
		11=>'November',
		12=>'Desember',
	);
	$bln = (int)date('m' ,strtotime($dperiode['tanggal']));
	$namabulan = $bulans[$bln]; 
	/*$query = "SELECT a.karyawan_id  
		FROM pr_gaji_komponen a
		INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id
		WHERE a.periode_id={$periode_id} 
		AND a.komponen_id={$komponen_id} 
		AND (b.nik BETWEEN {$_GET['nik_start']} AND {$_GET['nik_end']} )
		ORDER BY b.karyawan_id  "
	;  */
	$query = "
			SELECT a.karyawan_id,a.nominal FROM pr_yearly_income_karyawan a
			INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id 
			WHERE a.komponen_id={$komponen_id}  
			AND pr_yearly_income_id ={$pr_yearly_income_id} AND a.nominal <> 0  
		AND b.karyawan_id NOT IN (select karyawan_id FROM pemberhentian  ) 
		AND b.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
			ORDER BY b.nik ASC
		";	
	$result = my_query($query);
	$total_record = my_num_rows($result);
	
	$total_page = ceil($total_record/40);
	$grand_nominal=0;  
	for($n=1;$n<=$total_page;$n++):
	$st = ($n - 1 )*40;var_dump($st);
 ?>
 <?php echo str_pad('P.T.  K R A K A T A U  M E D I K A',65," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad( 'DATA '.strtoupper($komponen['label']),65," ", STR_PAD_BOTH); ?> 
 <?php echo str_pad('Yearly income  ( '. $filenamedt.' '.date('Y').' )',65," ", STR_PAD_BOTH); ?> 
  <?php echo str_repeat('_',66); ?> 
 <?php echo str_pad( 'NO',6," ",STR_PAD_BOTH). str_pad( 'N.I.K',9 ). str_pad( 'N A M A',30 ).str_pad('JUMLAH',20," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',66); 
	 
	$query2 = "
			SELECT a.karyawan_id,a.nominal FROM pr_yearly_income_karyawan a
			INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id 
			WHERE a.komponen_id={$komponen_id}  AND pr_yearly_income_id ={$pr_yearly_income_id} AND a.nominal <> 0
			
			
		AND b.karyawan_id NOT IN (select karyawan_id FROM pemberhentian  ) 
		AND b.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
			ORDER BY b.nik ASC  LIMIT {$st},40
		";	
	$result2 = my_query($query2);
	$i=$st;
	$nominal_page =0;
	while($ey = my_fetch_array($result2)){
	$i++;
	$karyawan_temp=$ey['karyawan_id'];
	$karyawan = loaddata_karyawan($ey['karyawan_id']);
	$nominal_page += $ey['nominal'];
	$grand_nominal +=$ey['nominal'];
 ?> 
 <?php echo str_pad( $i.'  ',6," ",STR_PAD_LEFT). str_pad($karyawan['nik'] ,9 ). str_pad( $karyawan['nama'] ,30 ).str_pad(rp_format($ey['nominal']),20," ",STR_PAD_LEFT); ?>  <?php if(($i%5) ==0 && ($i%40) !=0)echo "\n";
 }
 ?> 
 <?php echo str_repeat('_',66); ?> 
 <?php echo str_pad( 'Total',6," ",STR_PAD_BOTH). str_pad( ' ',9 ). str_pad( ' ',30 ).str_pad(rp_format($nominal_page) ,20," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',66); ?> 
 <?php echo str_pad( ' Grand Total',15 ) . str_pad( ' ',30 ).str_pad(rp_format($grand_nominal) ,20," ",STR_PAD_LEFT); ?> 
 <?php echo str_repeat('_',66); ?>
 
 <?php if( $n == $total_page){  echo "\n\n "; 
  $bl = (int)date('m'); echo str_pad( str_pad('Cilegon, '.date('d').' '.$bulans[$bl].' '.date('Y').'     '  , 25, " ", STR_PAD_BOTH ),65," ",STR_PAD_LEFT); 
   echo "\n\n\n\n\n\n";
 
 echo str_pad( '('.str_pad( MAN_DEPARTEMEN_HEAD_OFFICE_NAME ,25," ",STR_PAD_BOTH).')  ',65," ",STR_PAD_LEFT);  
echo "\n";
 echo str_pad( ' '.str_pad( MAN_DEPARTEMEN_HEAD_OFFICE ,25," ",STR_PAD_BOTH).'   ',65," ",STR_PAD_LEFT); 
 } ?><P><?php   
 endfor; 
 ?>
	<?php
	echo'
	
<script>
function breakeveryheader(){
if (!document.getElementById){
	alert("You need IE5 or NS6 to run this example")
	return
}
var thestyle=  "always" ;
for (i=0; i<document.getElementsByTagName("P").length; i++)
	document.getElementsByTagName("P")[i].style.pageBreakBefore=thestyle
}
//window.print();
</script>   
</body> 
</html>';
exit;	
}
 